﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Presentation.Commands;
using Jbe.TestSuite.Infrastructure.Interface;
using System.ComponentModel;
using Jbe.Composite.Extensions;
using System.Windows.Input;
using System.Reflection;

namespace Jbe.TestSuite.Infrastructure.Shell.Applications
{
    internal class ShellPresentationModel : PresentationModel<IShellView>, IStatusMessageService
    {
        private static readonly PropertyInfo StatusMessageProperty = TypeManager.GetProperty<ShellPresentationModel>(x => x.StatusMessage);


        private readonly IShowAboutView showAboutView;
        private readonly DelegateCommand exitCommand;
        private readonly DelegateCommand showAboutCommand;
        private string statusMessage = "Ready";


        public ShellPresentationModel(IShellView view, IShowAboutView showAboutView)
            : base(view)
        {
            this.showAboutView = showAboutView;

            exitCommand = new DelegateCommand(Exit);
            showAboutCommand = new DelegateCommand(ShowAbout);
        }


        public ICommand ExitCommand { get { return exitCommand; } }

        public ICommand ShowAboutCommand { get { return showAboutCommand; } }

        public string Title { get { return ApplicationInfo.ProductName; } }

        public string StatusMessage
        {
            get { return statusMessage; }
            set
            {
                if (statusMessage != value)
                {
                    statusMessage = value;
                    RaisePropertyChanged(StatusMessageProperty);
                }
            }
        }


        public void Show()
        {
            View.Show();
        }

        public void Close()
        {
            View.Close();
        }

        void IStatusMessageService.UpdateMessage(string message)
        {
            StatusMessage = message;
        }

        private void Exit()
        {
            Close();
        }

        private void ShowAbout()
        {
            showAboutView.Show();
        }
    }
}
